#include "StdAfx.h"
#include "SessionHandler.hpp"

#include "ResipTesterDlg.hpp"

CSessionHandler::CSessionHandler(CResipTesterDlg& dlg, ISipTranSession& ts): 
m_dlg(dlg), m_ts(&ts), m_ds(0), m_id(ts.getHandle())
{
}


CSessionHandler::CSessionHandler(CResipTesterDlg& dlg, ISipDlgSessionBase& ds): 
m_dlg(dlg), m_ts(0), m_ds(&ds), m_id(ds.getHandle())
{
}


CSessionHandler::~CSessionHandler(void)
{
    if (m_ts){
        m_ts->unregisterHandle(this);
    } else if (m_ds){
        m_ds->unregisterHandle(this);
    }
}


/////////////////// Transaction Handle ////////////////////////////

bool CSessionHandler::onRequest(ISipTranSession& tran, const SHeaders& headers, const SMsgBodyBase& body)
{
    m_dlg.pushLogText(body.contents, m_dlg.m_BodyMonitor);
    SHeaders rHeaders;
    rHeaders.eCode = m_dlg.isFailedCheck() ? wtsip::BADREQUEST: wtsip::ACCEPTED;
    tran.reply(rHeaders);
    return true;
}


bool CSessionHandler::onResponse(ISipTranSession& tran, const SHeaders& headers, const SMsgBodyBase& body)
{
    m_dlg.pushLogText(body.contents, m_dlg.m_BodyMonitor);
    SHeaders rHeaders;
    rHeaders.eCode = m_dlg.isFailedCheck() ? wtsip::BADREQUEST: wtsip::ACCEPTED;
    tran.reply(rHeaders);
    return true;
}


bool CSessionHandler::onState(ISipTranSession& tran, const ISipTranSession::ETranSessionState newState)
{
    return true;
}


bool CSessionHandler::onDestroy(ISipTranSession& tran)
{
    return true;
}

///////////////////// Dialog Handle ///////////////////////////

bool CSessionHandler::onRequest(ISipDlgSessionBase& dlg, const SHeaders& headers, 
                       const SMsgBodyBase& body, ISipTranSession& srvTran)
{
    return true;
}


bool CSessionHandler::onResponse(ISipDlgSessionBase& dlg, const SHeaders& headers,
                        const SMsgBodyBase& body, ISipTranSession& clnTran)
{
    return true;
}


bool CSessionHandler::onState(ISipDlgSessionBase& dlg, const ISipDlgSessionBase::EDlgSessionState newState)
{
    return true;
}


bool CSessionHandler::onDestroy(ISipDlgSessionBase& dlg)
{
    return true;
}

